package com.jgp.security.shiro.config;

import lombok.extern.log4j.Log4j2;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;

/**
 * 项目   parent
 * 作者   loufei
 * 时间   2018/4/6
 */
@Order(400)
@Log4j2
@Configuration
@ConditionalOnProperty(prefix = "jgp.security", name = "enabled", matchIfMissing = true)
public class ShiroSecurityConfiguration {
    
    @Configuration
    @ConditionalOnProperty(prefix = "jgp.cache", name = "enabled", havingValue = "true")
    @Import(ShiroRedisConfiguration.class)
    class Configuration0{}
    
    @Configuration
    @ConditionalOnProperty(prefix = "jgp.cache", name = "enabled", havingValue = "false")
    @Import(NoRedisConfiguration.class)
    class Configuration1{}
    
   
    
    /**
     * cookie对象;
     * rememberMeCookie()方法是设置Cookie的生成模版，比如cookie的name，cookie的有效时间等等。
     *
     * @return
     */
   /* @Bean
    public SimpleCookie rememberMeCookie() {
        SimpleCookie simpleCookie = new SimpleCookie("jgp_remember_me");
        // 记住我cookie生效时间30天 ,单位秒
        simpleCookie.setMaxAge(259200);
        return simpleCookie;
    }*/
    
    
    /**
     * cookie管理对象;
     * rememberMeManager()方法是生成rememberMe管理器，而且要将这个rememberMe管理器设置到securityManager中
     *
     * @return
     */
   /* @Bean
    public CookieRememberMeManager rememberMeManager() {
        //System.out.println("ShiroConfiguration.rememberMeManager()");
        CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
        cookieRememberMeManager.setCookie(rememberMeCookie());
        //rememberMe cookie加密的密钥 建议每个项目都不一样 默认AES算法 密钥长度(128 256 512 位)
        cookieRememberMeManager.setCipherKey(Base64.decode("2AvVhdsgUs0FSA3SDFAdag=="));
        return cookieRememberMeManager;
    }*/
    
}
